﻿using System;
using System.Net;
using System.Collections.Generic;
using SomeKit.Serialization;

#if WINDOWS_PHONE
using Microsoft.Phone.Reactive;
#else
using System.Linq;
#endif
using SomeKit.Rx.Http;
namespace SomeKit.Rx.TypeSafe
{
    public static partial class ClientHelper
    {
        public static IObservable<RESULT> Get<RESULT>(this Uri uri,Func<string, RESULT> deserializer, Action<HttpWebRequest> headerHandler = null)
        {
            return uri.Get(headerHandler).Select(s => deserializer(s));
        }
        public static IObservable<RESULT> GetXml<RESULT>(this Uri uri, Action<HttpWebRequest> headerHandler = null)
        {
            return uri.GetXml(headerHandler).Select(s => s.DeserializeXml<RESULT>());
        }
        public static IObservable<RESULT> GetJson<RESULT>(this Uri uri, Action<HttpWebRequest> headerHandler = null)
        {
            return uri.GetJson(headerHandler).Select(s => s.DeserializeJson<RESULT>());
        }
    }
}
